﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.DAL;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Inventory_Stock_Taking : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        D_IcmInventoryStockTaking d_stock_taking = new D_IcmInventoryStockTaking();
        M_IcmInventoryStockTaking m_stock_taking = new M_IcmInventoryStockTaking();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadGrid();
                grdCheckStock.DataBind();
                btnInsert.OnClientClick = "openStautsAdd()";
            }
        }
        protected void btnInsert_OnClick(object sender, EventArgs e)
        {
        }
        protected void grdCheckStock_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            LoadGrid();
        }
        protected void grdCheckStock_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "DataDelete")
                {
                    try
                    {
                        M_IcmInventoryStockTaking info = d_stock_taking.GetListFillBySeq(grdCheckStock.Items[e.Item.ItemIndex]["icm_stock_taking_code"].Text);
                        m_stock_taking.icm_stock_taking_code = info.icm_stock_taking_code.ToString();
                        m_stock_taking.record_status = "D";
                        m_stock_taking.updated_by = cn.UserID;
                        m_stock_taking.updated_when = DateTime.Now;
                        d_stock_taking.Delete_Stock_Taking(m_stock_taking);
                    }
                    catch (Exception ex)
                    {
                        RadAjaxManager1.Alert("เกิดข้อผิดพลาดระหว่างลบข้อมูล");
                        throw (ex);
                    }
                    finally
                    {
                        LoadGrid();
                        grdCheckStock.DataBind();
                    }
                }
        }
        private void LoadGrid()
        {
            grdCheckStock.DataSource = d_stock_taking.GetList();
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            LoadGrid();
            grdCheckStock.Rebind();
        }
    }
}
